blob: 46278c878e7f2021db2d7f626c13b576e99a1ddf (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
import dbConnect from 'lib/dbConnect'
import withSession from 'lib/withSession'
import Note from 'models/Note'
export default withSession(async (req, res) => {
const {id} = req.query
await dbConnect()
switch (req.method) {
case 'GET':
try {
const user = req.session.get('user')
if (!user || !user?.isVerified || !id ) {
throw new Error('Something went wrong')
}
const note = await Note.getNote(id)
if (!note) {
throw new Error('Something went wrong')
}
res.status(200).json(note)
} catch (error) {
console.log(error)
res.status(400).json({error: true})
}
break
}
})
|